{{ $item := .item }}
{{ $widget := .page }}
{{ $index := .index }}

{{ $do_link := true }}
{{ if $item.Params.external_link | or $item.Content }}
  {{ $do_link = true }}
{{ else }}
  {{ $do_link = false }}
{{ end }}

{{ $link := $item.Params.external_link | default $item.RelPermalink }}
{{ $target := .target }}

{{/* Get summary. */}}
{{ $summary := "" }}
{{ if $item.Params.summary }}
  {{ $summary = $item.Params.summary | markdownify | emojify }}
{{ else if $item.Params.abstract }}
  {{ $summary = $item.Params.abstract | markdownify | emojify }}
{{ else if $item.Summary }}
  {{ $summary = $item.Summary }}
{{ end }}

{{ $order := "" }}
{{ if isset $widget "Params" }}
  {{ if and ($widget.Params.design.flip_alt_rows | default true) (not (modBool $index 2)) }}
    {{ $order = "order-md-2" }}
  {{ end }}
{{ else if and ($widget.design.flip_alt_rows | default true) (not (modBool $index 2)) }}
  {{ $order = "order-md-2" }}
{{ end }}


<div class="col-lg-12 mb-5 view-showcase">
  <div class="row align-items-center">
    <div class="col-12 col-md-6">
      <div class="section-subheading article-title mb-0 mt-0">
        {{- if $do_link}}<a href="{{ $link }}" {{ $target | safeHTMLAttr }}>{{end -}}
        {{ $item.Title | markdownify | emojify }}
        {{- if $do_link}}</a>{{end -}}
      </div>

      {{ with $summary }}
      <div class="article-style">
        {{ . }}
      </div>
      {{ end }}

      <div class="btn-links">
        {{ partial "page_links" (dict "page" $item "is_list" 0) }}
      </div>

    </div>
    <div class="col-12 col-md-6 order-first {{$order}}">
      {{ $resource := partial "wowchemy-core/functions/get_featured_image.html" $item }}

      {{ with $resource }}
        {{/* Use CSS to expand images to consistent widths rather than just Hugo as Hugo can significantly increase the
        filesize of GIFs when processing them, e.g. 400kB --> 1.5MB */}}
        {{ $image := . }}
        {{ if ne $image.MediaType.SubType "gif" }}{{ $image = $image.Process "resize 540x webp" }}{{ end }}
        {{if $do_link}}<a href="{{ $link }}" {{ $target | safeHTMLAttr }}>{{end}}
          <img src="{{ $image.RelPermalink }}" height="{{ $image.Height }}" width="{{ $image.Width }}"
              alt="{{ $item.Title }}" loading="lazy" style="width: 540px; height: auto; object-fit: cover;">
        {{if $do_link}}</a>{{end}}
      {{end}}
    </div>
  </div>
</div>
